package com.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class DBUtil {
	private static String url="jdbc:mysql://localhost:3306/newsdb?"+"user=root&password=&characterEncoding=utf-8";
	private static 	String driver="com.mysql.cj.jdbc.Driver";
	
	static {
		try {
			Class.forName(driver);
		}
		catch(ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection() {
		try {
			Connection conn=DriverManager.getConnection(url);
			return conn;
		}
		catch(SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static void free(Connection conn,PreparedStatement  pstmt,ResultSet rs) {
		try {
			if(conn!=null)
				conn.close();
		}
		catch(SQLException e) {
			e.printStackTrace();
		}	
		try {
			pstmt.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	
}
